import { _decorator, Component, Node, SystemEvent, systemEvent, Touch, EventTouch } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('PlaneSelf')
export class PlaneSelf extends Component {
    @property
    public speed = 2;

    @property
    public constant = 0.01;

    onEnable() {
        systemEvent.on(SystemEvent.EventType.TOUCH_START, this.__touch_start, this);
        systemEvent.on(SystemEvent.EventType.TOUCH_MOVE, this.__touch_move, this);
    }

    start() {}

    // -----------------------------------

    __touch_start(touch: Touch, event: EventTouch) {}

    __touch_move(touch: Touch, event: EventTouch) {
        const delta = touch.getDelta();
        let pos = this.node.position;
        this.node.setPosition(pos.x + this.constant * this.speed * delta.x, pos.y, pos.z - this.constant * this.speed * delta.y);
    }
}
